package com.geektime.hello.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: DRevelation
 * @Date: 2021/3/13 16:44
 */
@RestController
@RequestMapping("rabbitmq")
public class RabbitMQController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @PostMapping("produce")
    public String produce(String msg) {
        rabbitTemplate.convertAndSend("spring-exchange", "spring-routing-key", msg);
        return "SUCCESS";
    }

    @GetMapping("consume")
    public Object consume() {
        return rabbitTemplate.receiveAndConvert("spring-queue");
    }
}
